package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;

/**
 * Test Kit for Power Statistic for a given timestamp - checks that min/max/average power returned
 * is correct.
 * 
 * @author Remy Baumgarten
 * @author Kevin Chiogioji
 * 
 */
public class TestPowerStatistic {

  private static final String source = "SIM_KAHE_2";
  private static final String date = "2009-10-31";
  private static final String gen = "generated";
  private static final String con = "consumed";

  /**
   * MinPowerGenerated.
   * 
   * @throws Exception -
   */
  @Test
  public void minPowerGen() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add(gen);
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("min");
    System.out.println("PowerStatistic Class:  Testing output for min power generated..");
    assertTrue("Checking min power generated for SIM_KAHE_2 on 2009-10-31", power.doCommand(args)
        .contains("5.1E7"));
  }

  /**
   * Max Power Generated.
   * 
   * @throws Exception -
   */
  @Test
  public void maxPowerGen() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add(gen);
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("max");
    System.out.println("PowerStatistic Class:  Testing output for max power generated..");
    assertTrue("Checking max power generated for SIM_KAHE_2 at 2009-10-31", power.doCommand(args)
        .contains("8.8E7"));
  }

  /**
   * Average Power Generated.
   * 
   * @throws Exception -
   */
  @Test
  public void avePowerGen() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add(gen);
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("average");
    System.out.println("PowerStatistic Class:  Testing output for average power generated..");
    assertTrue("Checking average power generated for SIM_KAHE_2 at 2009-10-31", power.doCommand(
        args).contains("7.954166666666667E7"));
  }

  /**
   * Min Power Consumed.
   * 
   * @throws Exception -
   */
  @Test
  public void minPowerConsumed() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add(con);
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("min");
    System.out.println("PowerStatistic Class:  Testing output for min power consumed..");
    assertTrue("Checking min power consumed for SIM_KAHE_2 at 2009-10-31", power.doCommand(args)
        .contains("0.0"));
  }

  /**
   * Max Power Consumed.
   * 
   * @throws Exception -
   */
  @Test
  public void maxPowerConsumed() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add(con);
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("max");
    System.out.println("PowerStatistic Class:  Testing output for max power consumed..");
    assertTrue("Checking max power consumed for SIM_KAHE_2 at 2009-10-31", power.doCommand(args)
        .contains("0.0"));
  }

  /**
   * Average Power Consumed.
   * 
   * @throws Exception -
   */
  @Test
  public void averagePowerConsumed() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add(con);
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("average");
    System.out.println("PowerStatistic Class:  Testing output for average power consumed..");
    assertTrue("Checking average power consumed for SIM_KAHE_2 at 2009-10-31", power
        .doCommand(args).contains("0.0"));
  }

  /**
   * Test Input Validation 1.
   * 
   * @throws Exception -
   */
  @Test
  public void testInputValidation() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add("fake_value"); // bad value
    args.add(source);
    args.add(date);
    args.add("60");
    args.add("notsoaverage"); // bad value
    System.out.println("Checking input validation..." + power.doCommand(args));
    assertTrue("Checking input validation for ", power.doCommand(args).contains(
        "Invalid TimeStamp Formatting"));
  }

  /**
   * Test Input Validation 2.
   * 
   * @throws Exception -
   */
  @Test
  public void testInputValidation2() throws Exception {
    PowerStatistic power = new PowerStatistic();
    List<String> args = new ArrayList<String>();
    args.add("generated");
    args.add(source);
    args.add(date);
    args.add("bob"); // not a number
    args.add("max");
    System.out.println("Checking input validation..." + power.doCommand(args));
    assertTrue("Checking input validation for ", power.doCommand(args).contains(
        "Your specified interval is not a number"));
  }

}
